/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ventana2.java
 *
 * Created on 04/06/2011, 09:06:04 PM
 */

package interfazop;

import Estructuras.*;
import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JList;

/**
 *
 * @author necross
 */
public class ventana2 extends javax.swing.JFrame {

    //apunatador al panel de schedulelr
    
    public static pintarSobreVentana psv;

   
    /** Creates new form ventana2 */
    public ventana2() {
        initComponents();
        this.psv = new pintarSobreVentana(this);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelSimulador = new javax.swing.JLabel();
        jLabelCpu = new javax.swing.JLabel();
        CpuImagen = new javax.swing.JLabel();
        jLabelImagenIO = new javax.swing.JLabel();
        jLabelIO = new javax.swing.JLabel();
        jLabelTask_List = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanelSched = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jScrollPaneTaskList = new javax.swing.JScrollPane();
        jPanelTaskList = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPaneCPU = new javax.swing.JScrollPane();
        jScrollPaneIO = new javax.swing.JScrollPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanelColaIO = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jButtonTimer = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jPanelLog = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanelSched2 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("SegundaVentana"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(interfazop.InterfazOpApp.class).getContext().getResourceMap(ventana2.class);
        jLabelSimulador.setFont(resourceMap.getFont("jLabelSimulador.font")); // NOI18N
        jLabelSimulador.setText(resourceMap.getString("jLabelSimulador.text")); // NOI18N
        jLabelSimulador.setName("jLabelSimulador"); // NOI18N

        jLabelCpu.setFont(resourceMap.getFont("jLabelCpu.font")); // NOI18N
        jLabelCpu.setText(resourceMap.getString("jLabelCpu.text")); // NOI18N
        jLabelCpu.setName("jLabelCpu"); // NOI18N

        CpuImagen.setIcon(resourceMap.getIcon("CpuImagen.icon")); // NOI18N
        CpuImagen.setText(resourceMap.getString("CpuImagen.text")); // NOI18N
        CpuImagen.setName("CpuImagen"); // NOI18N

        jLabelImagenIO.setIcon(resourceMap.getIcon("jLabelImagenIO.icon")); // NOI18N
        jLabelImagenIO.setText(resourceMap.getString("jLabelImagenIO.text")); // NOI18N
        jLabelImagenIO.setName("jLabelImagenIO"); // NOI18N

        jLabelIO.setFont(resourceMap.getFont("jLabelIO.font")); // NOI18N
        jLabelIO.setText(resourceMap.getString("jLabelIO.text")); // NOI18N
        jLabelIO.setName("jLabelIO"); // NOI18N

        jLabelTask_List.setFont(resourceMap.getFont("jLabelTask_List.font")); // NOI18N
        jLabelTask_List.setText(resourceMap.getString("jLabelTask_List.text")); // NOI18N
        jLabelTask_List.setName("jLabelTask_List"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jPanelSched.setName("jPanelSched"); // NOI18N
        jPanelSched.setLayout(new javax.swing.BoxLayout(jPanelSched, javax.swing.BoxLayout.Y_AXIS));
        jScrollPane1.setViewportView(jPanelSched);

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jScrollPaneTaskList.setName("jScrollPaneTaskList"); // NOI18N

        jPanelTaskList.setName("jPanelTaskList"); // NOI18N
        jPanelTaskList.setLayout(new javax.swing.BoxLayout(jPanelTaskList, javax.swing.BoxLayout.LINE_AXIS));
        jScrollPaneTaskList.setViewportView(jPanelTaskList);

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS));

        jScrollPaneCPU.setName("jScrollPaneCPU"); // NOI18N

        jScrollPaneIO.setName("jScrollPaneIO"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jPanelColaIO.setName("jPanelColaIO"); // NOI18N
        jPanelColaIO.setLayout(new javax.swing.BoxLayout(jPanelColaIO, javax.swing.BoxLayout.LINE_AXIS));
        jScrollPane3.setViewportView(jPanelColaIO);

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jButtonTimer.setText(resourceMap.getString("jButtonTimer.text")); // NOI18N
        jButtonTimer.setName("jButtonTimer"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jPanelLog.setName("jPanelLog"); // NOI18N
        jPanelLog.setLayout(new javax.swing.BoxLayout(jPanelLog, javax.swing.BoxLayout.Y_AXIS));
        jScrollPane4.setViewportView(jPanelLog);

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jPanelSched2.setName("jPanelSched2"); // NOI18N
        jPanelSched2.setLayout(new javax.swing.BoxLayout(jPanelSched2, javax.swing.BoxLayout.Y_AXIS));
        jScrollPane2.setViewportView(jPanelSched2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(567, Short.MAX_VALUE)
                .addComponent(jLabelSimulador)
                .addGap(355, 355, 355))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(18, 18, 18)
                                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(46, 46, 46)
                                                .addComponent(jButtonTimer, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(63, 63, 63)
                                                .addComponent(jLabel5)))
                                        .addGap(18, 18, 18)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabel3)
                                        .addGap(65, 65, 65)
                                        .addComponent(jLabel1)
                                        .addGap(102, 102, 102)
                                        .addComponent(jLabel4)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(5, 5, 5)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(119, 119, 119)
                                                .addComponent(jLabelCpu))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(28, 28, 28)
                                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(49, 49, 49)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabelIO, javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addComponent(jLabelImagenIO, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(CpuImagen, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(26, 26, 26)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addComponent(jScrollPaneIO, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jScrollPaneCPU, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(109, 109, 109)
                                        .addComponent(jLabel2))))
                            .addComponent(jScrollPaneTaskList, javax.swing.GroupLayout.PREFERRED_SIZE, 712, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(144, 144, 144)
                .addComponent(jLabelTask_List)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 649, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addGap(153, 153, 153))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelSimulador)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTask_List)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPaneTaskList, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabelCpu))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(4, 4, 4)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel1)
                                            .addComponent(jLabel4))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                            .addComponent(jScrollPaneCPU)
                                                            .addComponent(CpuImagen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jLabelIO)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                            .addComponent(jScrollPaneIO)
                                                            .addComponent(jLabelImagenIO, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                                                        .addComponent(jLabel2)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 118, Short.MAX_VALUE)
                                                .addComponent(jLabel5)
                                                .addGap(18, 18, 18)
                                                .addComponent(jButtonTimer, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(24, 24, 24)))))
                                .addGap(36, 36, 36))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addContainerGap(375, Short.MAX_VALUE))))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        //Al apretar boton de agregar proceso
        //psv.agregar();
        //jPanelSched.revalidate();
        this.Iniciar();
        jButton3.setEnabled(false);
        
        //jPanelSched.repaint();
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ventana2().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel CpuImagen;
    private javax.swing.JButton jButton3;
    protected javax.swing.JButton jButtonTimer;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabelCpu;
    private javax.swing.JLabel jLabelIO;
    private javax.swing.JLabel jLabelImagenIO;
    private javax.swing.JLabel jLabelSimulador;
    private javax.swing.JLabel jLabelTask_List;
    private javax.swing.JPanel jPanel1;
    protected javax.swing.JPanel jPanelColaIO;
    protected javax.swing.JPanel jPanelLog;
    protected javax.swing.JPanel jPanelSched;
    protected javax.swing.JPanel jPanelSched2;
    protected javax.swing.JPanel jPanelTaskList;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    protected javax.swing.JScrollPane jScrollPaneCPU;
    protected javax.swing.JScrollPane jScrollPaneIO;
    private javax.swing.JScrollPane jScrollPaneTaskList;
    // End of variables declaration//GEN-END:variables

    
    
    
   /**
    * Retorna la clase para pintar sobre la ventana
    */
    public pintarSobreVentana getPsv() {
        return psv;
    }
    
    
    ///                      MAIN
    
    /**
     Para El Main
     */
    
    
    
     public static void crearTimer(){
//Instanciar el timer
      TimerH th = new TimerH();
      int tiempoEjecucion = Configuracion.tiempoEjecucion;
      //objeto que usara timer
       //CPU U SHCHEDULER

      //se agrega el objeto observador al objeto observado



      th.addObserver(CPU); //CPU
      //th.addObserver(sc); //scheduler
      th.addObserver(so);
      //th.addObserver(IO); //IO

      //inicia hilo de timer
      Thread hiloTimer = new Thread(th);
      hiloTimer.start();
    try {
      
      Thread.sleep(tiempoEjecucion);
    } catch (InterruptedException ex) {
      Logger.getLogger(ventana2.class.getName()).log(Level.SEVERE, null, ex);
    }
      //detiene el hilo
      th.detener();

    }
    
    
 private static Scheduler sc;

  //CPU
  private static Cpu_struct CPU;

  //DISPOSITIVO OI
  private static IO_struct IO;

  //Sistema Operativo
  private static SO so;
    
  public void Iniciar(){
        principal p = new principal();
        Thread ini = new Thread(p);
        ini.start();
  }
    
    

  
private class principal implements Runnable{

        public void run() {
            Iniciar();
        }
        
        
        public void Iniciar(){
        //Scheduler
  
       //Se crean unos procesos
        sched_entity se = new sched_entity(5, 4, 3, 2);
        Task_struct ts1 = new Task_struct();
        ts1.setPid(101);
        ts1.setPrio((short)40);


        Task_struct ts2 = new Task_struct();

        ts2.setPid(102);
        ts2.setPrio((short)50);

        Task_struct ts3 = new Task_struct();
        ts3.setPid(103);
        ts3.setPrio((short)70);

        Task_struct ts4 = new Task_struct();
        ts4.setPid(104);
        ts4.setPrio((short)40);

        Task_struct ts5 = new Task_struct();
        ts5.setPid(105);
        ts5.setPrio((short)40);
        
        
         //crea Scheduler
        sc = new Scheduler();

        //Sistema Operativo
        so = new SO(sc);

       
        
        //Se crea el CPU
        CPU = new Cpu_struct(sc);

        //Se crea unidad de IO
        IO = new IO_struct(sc);
        

         //Agregar proceso al SO
        so.crearProceso(ts1);
        so.crearProceso(ts2);
        so.crearProceso(ts3);
        so.crearProceso(ts4);
        so.crearProceso(ts5);

        //Creamos un TIMER INICIA EJECUCION
        crearTimer();
        
    
  }


}
   
    

    
    
}
